import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Allen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Allen extends Enemigo
{
    /**
     * Act - do whatever the Flecha wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private GreenfootImage [] allen;
    private GreenfootImage [] allenDispara;
    private GreenfootImage [] allenLeft;
    private GreenfootImage [] allenDisparaLeft;
    
    private int delay =0;
    private int sprite=0;
    private boolean dispara=false;
    private int limiteSprite;
    private int direccion;
    public Allen(int dir)
    {
        super(60);
        direccion=dir;
        allen=new GreenfootImage[16];
        allenDispara=new GreenfootImage[8];
         allenLeft=new GreenfootImage[16];
        allenDisparaLeft=new GreenfootImage[8];
        
         for(int i=1; i<=allen.length; i++)
        {
            allen[i-1] = new GreenfootImage("Allen"+i+".png");
            allen[i-1].scale(allen[i-1].getWidth()*2,allen[i-1].getHeight()*2);
            allenLeft[i-1] = new GreenfootImage("Allen"+i+".png");
            allenLeft[i-1].scale(allenLeft[i-1].getWidth()*2,allenLeft[i-1].getHeight()*2);
            allenLeft[i-1].mirrorHorizontally();
        }
        
         for(int i=1; i<=allenDispara.length; i++)
        {
            allenDispara[i-1] = new GreenfootImage("AllenDispar"+i+".png");
           allenDispara[i-1].scale(allenDispara[i-1].getWidth()*2,allenDispara[i-1].getHeight()*2);
           allenDisparaLeft[i-1] = new GreenfootImage("AllenDispar"+i+".png");
           allenDisparaLeft[i-1].scale(allenDisparaLeft[i-1].getWidth()*2,allenDisparaLeft[i-1].getHeight()*2);
           allenDisparaLeft[i-1].mirrorHorizontally();
        }
        limiteSprite=allen.length-1;
        setImage(allenLeft[sprite]);
    }
    public void act() 
    {
        animacion();
        if(dispara==true && sprite == 4)
        {
            this.dispara();
        }
        super.act();
        
        // Add your action code here.
    }    
     public void animacion()
    {
       
        if(delay==4)
        {
            delay=0;
            
            if(sprite==limiteSprite){
            if(dispara==true)
            {
            dispara=false;
            setLocation(getX()-10,getY()+23);
            limiteSprite=allen.length-1;
            }
            else
            {
                dispara=true;
                setLocation(getX()+10,getY()-23);
                limiteSprite=allenDispara.length-1;
            }
            sprite=0;
        }
            if(dispara==false){
            if(direccion==1)
            setImage(allen[sprite]);
            else
            setImage(allenLeft[sprite]);
           }
            else
            {
                if(direccion==1)
                setImage(allenDispara[sprite]);
                else
                setImage(allenDisparaLeft[sprite]);
            }
            sprite++;
        }
        else
        delay++;
    }
    public void dispara()
    {
        getWorld().addObject(new misil(direccion,true),getX()+70*(direccion), getY()+30);
    }
}
